package com.techyuan.algorithm.sorts;

import com.techyuan.algorithm.utils.PrintUtil;
import com.techyuan.algorithm.utils.SortUtils;
import com.techyuan.algorithm.utils.test.BaseTest;
import com.techyuan.algorithm.utils.test.TestUtils;

/**
 * 时间复杂度符号
 * Ο 非紧确上界
 * Θ 紧确上界
 * Ω 非紧确下界
 * ω 紧确下界
 * 设置JVM的堆栈大小: -Xss50m
 *
 * @author tianjuntao
 */
public class SortMain {
    public static int[]sortingArr = null;


    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        int count = 13;
        int max = 100;
        createSortingList(count, max);
        runSort(new InsertionSort(),1);
        //runSort(new BubbleSort(), 1);
        //runSort(new HeapSort(), 1);
        //runSort(new QuickSort(), 1);
        //runSort(new CountingSort(max), 1);
        //runSort(new RadixSort(max), 1);
    }

    private static void runSort(final ISort sort, final int thread) {
        TestUtils.testRuntime(new BaseTest() {
            public String test() {
                int[] sortedArr = sort.sort(sortingArr);
                if (sortedArr.length < 10000)
                    PrintUtil.printArrPretty(sortedArr, "排序后：%s");
                return sort.getClass().getSimpleName();
            }
        }, thread);
    }

    public static void createSortingList(int count, int max) {
        if (sortingArr == null) {
            sortingArr = SortUtils.createRandomList(count, max);
            if (sortingArr.length < 10000)
                PrintUtil.printArrPretty(sortingArr, "排序前：%s");
        }
        System.out.println("数据生成完成!");
    }
}
